package com.jial08.designpatterns.prototype.shallow;

import java.util.Date;
import java.util.List;

/**
 * <p>类描述：clone 实现对象复制。</p>
 *
 * @author jl
 * @version v1.0.0.1。
 * @since JDK1.8。
 * <p>创建日期：2019/10/26 下午6:08。</p>
 *
 * 注：基于序列化和反序列化实现的克隆不仅仅是深度克隆，更重要的是通过泛型限定，可以检查出要克隆的对象是否支持序列化，这项检查是编译器完成的，
 * 不是在运行时抛出异常，这种是方案明显优于使用Object类的clone方法克隆对象。让问题在编译的时候暴露出来总是优于把问题留到运行时
 */
public class Student0 implements Cloneable {

	private static final long serialVersionUID = -9111812742820430930L;
	private int age;
	private Address0 address;
	private Date birthday;
	private Integer grade;
	private List<String> list;

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Address0 getAddress() {
		return address;
	}

	public void setAddress(Address0 address) {
		this.address = address;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}

	@Override
	protected Student0 clone() {
		Student0 student = null;
		try {
			student = (Student0) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return student;
	}

	@Override
	public String toString() {
		return "Student{" +
				"age=" + age +
				", address=" + address.getAdd() +
				", birthday=" + birthday +
				", grade=" + grade +
				", list=" + list +
				'}';
	}
}
